<!-- 组装记录查询 -->
<template>
  <basic-container>
    <avue-crud
      :option="option"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @on-load="onLoad"
    >
      <template slot="menuLeft">
        <el-button type="warning" size="small" icon="el-icon-download" @click="$refs.exportComp.visible = true">导出</el-button>
      </template>
      <template slot="menuRight">
        <user-table-config :option="option" @confirm="(val) => handleSetUserConfig(val, pageCode)"></user-table-config>
      </template>
    </avue-crud>
    <export-comp ref="exportComp" page-api-url="mes-product/product/assemble/list" :option="option" :page="page" :query="query" file-name="组装记录"></export-comp>
  </basic-container>
</template>

<script>
import { getList } from '@/api/product/assemblyRecordQuery';
import { mapGetters } from 'vuex';
import userTableConfig from '@/components/user-table-config';
import userConfig from '@/mixins/userConfig';
import exportComp from '@/components/export-comp';

export default {
  components: {
    userTableConfig,
    exportComp
  },
  mixins: [userConfig()],
  data() {
    return {
      pageCode: 'ASSEMBLY_RECORD_QUERY',
      form: {},
      query: {},
      loading: true,
      page: {
        pageSize: 20,
        currentPage: 1,
        total: 0
      },
      selectionList: [],
      option: {
        height: 'calc(100vh - 406px)',
        calcHeight: 30,
        tip: false,
        searchShow: true,
        searchMenuSpan: 4,
        searchLabelWidth: 100,
        labelWidth: 120,
        menu: false,
        menuWidth: 100,
        border: true,
        index: true,
        indexLabel: '序号',
        viewBtn: true,
        addBtn: false,
        delBtn: false,
        editBtn: false,
        selection: false,
        columnBtn: false,
        dialogClickModal: false,
        column: [
          {
            label: '工单号',
            prop: 'workOrderNo',
            search: true
          },
          {
            label: '产品序列号',
            search: true,
            prop: 'productSn'
          },
          {
            label: '产品编码',
            prop: 'productPartNo'
          },
          {
            label: '产品名称',
            prop: 'productPartName'
          },
          {
            label: '产品型号',
            prop: 'productPartModel'
          },
          {
            label: '子件序列号',
            prop: 'keyProductSn',
            search: true
          },
          {
            label: '子件编码',
            prop: 'assemblePartNo'
          },
          {
            label: '子件名称',
            prop: 'assemblepartName'
          },
          {
            label: '子件型号',
            prop: 'assemblePartModel'
          },
          {
            label: '组装人',
            width: 100,
            prop: 'componentUser'
          },
          {
            label: '组装工序',
            prop: 'routeName'
          },
          {
            label: '组装工序',
            prop: 'routeCode',
            type: 'select',
            hide: true,
            search: true,
            dicUrl: '/api/mes-product/apaasworkstation/page?type=ASSEMBLY&current=1&size=500',
            dicMethod: 'post',
            dicFormatter: (data) => {
              return data.data.records;
            },
            props: {
              label: 'name',
              value: 'code'
            }
          },
          // {
          //   label: '外部条码',
          //   prop: 'extendSequenceNumber',
          //   search: true
          // },
          {
            label: '组装时间',
            prop: 'componentTime',
            type: 'date',
            searchType: 'datetimerange',
            search: true,
            disabled: true,
            searchSpan: 12,
            format: 'yyyy-MM-dd HH:mm:ss',
            valueFormat: 'yyyy-MM-dd HH:mm:ss',
            startPlaceholder: '开始时间',
            endPlaceholder: '结束时间'
          },
          // {
          //   label: '子件条码类型',
          //   type: 'select',
          //   search: true,
          //   prop: 'productType',
          //   span: 4,
          //   labelWidth: 80,
          //   dicData: [
          //     { label: '内部条码', value: 'SELF' },
          //     { label: '外部条码', value: 'OUT' }
          //   ]
          // },
          {
            label: '状态',
            type: 'select',
            prop: 'actionType',
            span: 4,
            labelWidth: 80,
            dicData: [
              { label: '解绑状态', value: 'UNBINDING' },
              { label: '绑定状态', value: 'BINDING' }
            ]
          }
        ]
      },
      data: []
    };
  },
  computed: {
    ...mapGetters(['permission']),
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(',');
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.$structuralSplit();
    });
  },
  methods: {
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      if (this.query.componentTime) {
        this.query.startTime = this.query.componentTime[0];
        this.query.endTime = this.query.componentTime[1];
        delete this.query.componentTime;
      }
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    }
  }
};
</script>

<style></style>
